package com.mocoop.plugin.camera;



import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaArgs;
import org.apache.cordova.CordovaPlugin;
import org.json.JSONException;

import android.content.Intent;

import cn.imeth.android.camera.CameraActivity;

import com.mocoop.plugin.MocoopPlugin;

public class MyInnerCamera extends MocoopPlugin {

	
	private CallbackContext callbackContext;

	@Override
	public boolean execute(String action, CordovaArgs args, CallbackContext callbackContext) throws JSONException {

		this.callbackContext = callbackContext;
		Intent intent = new Intent(cordova.getActivity(), CameraActivity.class);
		intent.putExtra("square", false);

		try {
			cordova.startActivityForResult((CordovaPlugin) this, intent, 34);
		} catch (Exception e) {
			e.printStackTrace();
			callbackContext.error(e.getMessage());
		}
		return true;
	}

	@Override
	public void onActivityResult(int requestCode, int resultCode, Intent intent) {
		if (intent == null || intent.getData() == null)
			return;
		String imgPath = intent.getData().getPath();
		if (callbackContext != null)
			callbackContext.success("file://" + imgPath);

	}
}
